<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Commentstatus;
use common\models\CommentSearch;

/* @var $this yii\web\View */
/* @var $searchModel common\models\CommentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '评论管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comment-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <!-- <p>
        <?= Html::a('添加评论', ['create'], ['class' => 'btn btn-success']) ?>
    </p> -->
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            //['class' => 'yii\grid\SerialColumn'],

            [
            'attribute'=>'id',
            'contentOptions'=>['width'=>'30px'],
            ],
            [
            'attribute'=>'content',
            'value'=>'beginning',
            //function($model)
            //{
                //$tmpStr=strip_tags($model->content);
                //$tmpLen=mb_strlen($tmpStr);

                //return mb_substr($tmpStr,0,20,'utf-8').(($tmpLen>20)?'...':'');
            //}
            ],
            //'content:ntext',
            //'userid',
            [
            'attribute'=>'user.username',
            'label'=>'作者',
            'value'=>'user.username',
            ],
            [
            'attribute'=>'status',
            'value'=>'status0.name',
            'filter'=>Commentstatus::find()
                        ->select(['name','id'])
                        ->orderBy('position')
                        ->indexBy('id')
                        ->column(),
            'contentOptions'=>
                function($model)
                {
                    return ($model->status == 1)?['class'=>'bg-danger']:[];
                }
            ],
            //'create_time:datetime',
            [
            'attribute'=>'create_time',
            'format'=>['date','php:Y-m-d H:i'],
            ],
            // 'email:email',
            // 'url:url',
            //'post_id',
            //'post.title',
            [
            'attribute'=>'post.title',
            'label'=>'标题',
            'value'=>'post.title',
            ],
            [
            'class' => 'yii\grid\ActionColumn', //控制按钮类
            'template'=>'{view} {update} {delete} {approve}',   //按钮
            'buttons'=>     //动作
                [
                'approve'=>function($url,$model,$key)
                        {
                            $options=[
                                'title'=>Yii::t('yii', '审核'),
                                'aria-label'=>Yii::t('yii','审核'),
                                'data-confirm'=>Yii::t('yii','你确定通过这条评论吗？'),
                                'data-method'=>'post',
                                'data-pjax'=>'0',
                                    ];
                            return Html::a('<span class="glyphicon glyphicon-check"></span>',$url,$options);
                            
                        },
                ],
            ],
        ],
    ]); ?>
</div>
